package com.webside.front.detail.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import com.webside.front.common.mapper.BSeriesMapper;
import com.webside.front.common.mapper.BVideoMapper;
import com.webside.front.common.mapper.BdictionaryMapper;
import com.webside.front.common.mapper.PBannerMapper;
import com.webside.front.common.mapper.RCommentMapper;
import com.webside.front.common.model.BSeries;
import com.webside.front.common.model.BVideo;
import com.webside.front.common.model.Bdictionary;
import com.webside.front.common.model.PBanner;
import com.webside.front.common.model.RComment;
import com.webside.front.detail.service.IDetailService;

@Service("DetailServiceimpl")
public class DetailServiceImpl implements IDetailService{
	@Autowired
	public BSeriesMapper bSerierMapper;
	@Autowired
	public BVideoMapper bVideoMapper;
	@Autowired
	public RCommentMapper rCommentMapper;
	@Autowired
	public PBannerMapper pBannerMapper;
	@Autowired
	public BdictionaryMapper  bdictionary;

	@Override
	public BSeries selectSeriesById(Integer id) {
		return  bSerierMapper.selectByPrimaryKey(id);
		
	}
	
	//详细页面剧集选择
	@Override
	public List<BVideo> selectVideo(BVideo bVideoEntity) {
		return bVideoMapper.selectVideo(bVideoEntity);
	}

	@Override
	public List<BSeries> selectMayLike(BSeries bSeries) {
		return bSerierMapper.selectMayLike(bSeries);
	}

	@Override
	public Integer like(Integer videoId) {
		BVideo video=  bVideoMapper.selectByPrimaryKey(videoId);
		video.setLikeCount(video.getLikeCount()+1);
		bVideoMapper.updateVideoLikeCount(video);
		rCommentMapper.insertLike(video.getSeriesId(), videoId);
		return video.getLikeCount();
		
	}

	@Override
	public int insertComment(RComment record) {
		return rCommentMapper.insertSelective(record);
	}

	@Override
	public int insertUserComment(RComment record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<RComment> selectRComment(Integer videoId,Integer pageNo) throws Exception {
		Map<String,Object> condition= new HashMap<String,Object>();
		condition.put("id",videoId);
		condition.put("pageNo", pageNo*7);
		List<RComment> rComments = null;
		return rComments = rCommentMapper.selectRCommentByBVideoid(condition);
		
	}
	
	@Override
	public List<RComment> selectReplyComment(Integer videoId ,Integer pageNo ,Integer commentId) throws Exception {
		Map<String,Object> condition= new HashMap<String,Object>();
		condition.put("id",videoId);
		condition.put("parentId", commentId);
		condition.put("pageNo", pageNo*5);
		List<RComment> rComments = null;
		
			return rComments = rCommentMapper.selectReplyCommentByParentid(condition);
		
	}

	@Override
	public int delectRComment(RComment rcomment) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int reportRComment(RComment rcomment) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int LikeRComment(RComment record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public BVideo showVideoMsg(Integer videoId) {
		BVideo video = new BVideo();
		return video=bVideoMapper.selectByPrimaryKey(videoId);
	}
	//返回剧集集合
	@Override
	public List<BVideo> selectVideoBySeriesId(Integer seriesId) {
		return bVideoMapper.selectVideoBySId(seriesId);
	}

	@Override
	public Integer play(BVideo video) {
		bVideoMapper.updateVideoPlayCount(video);
		return video.getPlayCount();
	}

	@Override
	public int CommentCount(Integer videoId) {
		Map<String,Object> condition= new HashMap<String,Object>();
		condition.put("id",videoId);
		int Count = 0;
		return Count = rCommentMapper.selectCommentCount(condition);
	}

	@Override
	public int ReplyCount(Integer commentId) {
		Map<String,Object> condition= new HashMap<String,Object>();
		condition.put("parentId",commentId);
		int Count = 0;
		return Count = rCommentMapper.selectReplyCount(condition);

	}

	@Override
	public List<PBanner> selectBannerById(Integer id) {
		// TODO Auto-generated method stub
		return pBannerMapper.selectBannerById(id);
	}

	@Override
	public List<BSeries> selectMayChannel(BSeries record) {
		// TODO Auto-generated method stub
		return bSerierMapper.selectMayChannel(record);
	}

	@Override
	public List<RComment> selectByVideo(Integer videoId) {
		// TODO Auto-generated method stub
		return rCommentMapper.selectByVideo(videoId);
	}

	@Override
	public int addCount(RComment record) {
		// TODO Auto-generated method stub
		return rCommentMapper.addCount(record);
	}

	@Override
	public List<Bdictionary> selectKeywords() {
		// TODO Auto-generated method stub
		return bdictionary.queryBdictionarysKeywords();
	}

	
	
	
	
}
